package com.ctsi.product.service;

import com.ctsi.commons.util.UtilValidate;
import com.ctsi.commons.util.id.UUIDGenerator;
import com.ctsi.commons.util.response.Page;
import com.ctsi.framework.mybatis.support.MybatisGenericDao;
import com.ctsi.product.entity.Upload;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


 /**
  * Upload Service 类
  * @author   liuhx
  * @description  Upload
  * @created	 Sun Nov 18 16:13:14 CST 2018
  */

 @Service
 public class UploadService {
     private static final Logger logger=LoggerFactory.getLogger(UploadService.class);
     @Autowired
     private MybatisGenericDao dao;

     /**
      * 添加
      */
     public void insertUpload(Upload upload){
         if(UtilValidate.isEmpty(upload.getId()))
             upload.setId(UUIDGenerator.getId());
         logger.debug("insert {}",upload);
         dao.insert(upload);
     }
     /**
      * 动态更新
      */
     public int updateUploadByPKSelective(Upload upload){
         logger.debug("updateByPrimaryKeySelective {}",upload);
         return dao.update(Upload.class.getName()+".updateByPrimaryKeySelective", upload);
     }
     /**
      * 更新
      */
     public int updateUpload(Upload upload){
         logger.debug("update {}",upload);
         return dao.update(upload);
     }


     public Upload editUploadById(String id){
         if(UtilValidate.isEmpty(id))
             return null;
         logger.debug("editById {}",id);
         return (Upload)dao.queryForObject(Upload.class.getName()+".edit", id);
     }
     /**
      * 根据ID查找 Upload对象
      */
     public Upload findUploadById(String id){
         if(UtilValidate.isEmpty(id))
             return null;
         logger.debug("findById {}",id);
         return dao.get(Upload.class, id);
     }
     /**
      * 删除Upload对象
      */
     public int removeUpload(String id){
         if(UtilValidate.isNotEmpty(id))
             return dao.delete(Upload.class.getName()+".delete", id);
             //return dao.remove(id);
         return 0;
     }
     /**
      * 删除Upload对象
      */
     public int deleteFile(String id){
         if(UtilValidate.isNotEmpty(id))
             return dao.delete(Upload.class.getName()+".deleteByPrimaryKey", id);
         return 0;
     }
     /**
      * 详细页查询
      */
     public Upload findByDetail(String id){
         return (Upload)dao.queryForObject(Upload.class.getName()+".findByDetail",id);
     }
     /**
      * 多条件查询结果
      */
     public Page<Upload> findByMulitCondition(Map<String,Object> param , int start , int pageSize){
         logger.debug("findByMulitCondition {}",param);
         if(pageSize<0||pageSize>2000)
             pageSize=Page.DEFAULT_PAGE_SIZE;
         if(start!=-1)
             return dao.queryPage(Upload.class.getName()+".selectMulitCondition", param, start, pageSize);
         else{
             throw new RuntimeException("参数不正确 !!");
         }
     }
     /**
      * 多条件查询结果不分页
      */
     public List<Upload> find(Map<String,Object> map){
         logger.debug("find {}",map);
         return (List<Upload>)dao.queryForList(Upload.class.getName()+".selectByMap",map);
     }

 }
